import Vue from "vue";
export const getProjectList = ({ commit, dispatch, state }, data) => {
  // async fetch ...
  // 获取当前用户的项目列表
  return Vue.prototype.$http.project.getProjects().then(list => {
    commit("setProjects", list);
    let [, search] = location.hash.split("?");
    if (search) {
      let params = new URLSearchParams("?" + search);

      if (params.has("project_id")) {
        let current = list.find(({ id }) => id == params.get("project_id"));
        commit("initProject", current);
      }
    }
  });
};
